using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Remoting;
using System.Collections;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Serialization.Formatters;

using MULENetworking;

namespace MULEConsoleServer
{
    class ConsoleServer
    {
        private TcpChannel tcpChan;
        private int tcpPort = 9887;

        public ConsoleServer()
        {
            BinaryClientFormatterSinkProvider clientProvider = null;
            BinaryServerFormatterSinkProvider serverProvider =
               new BinaryServerFormatterSinkProvider();

            serverProvider.TypeFilterLevel =
                System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            IDictionary props = new Hashtable();
            props["port"] = tcpPort;
            props["typeFilterLevel"] = TypeFilterLevel.Full;
            tcpChan = new TcpChannel(
                props, clientProvider, serverProvider);

            ChannelServices.RegisterChannel(tcpChan, false);

        }

        public void StartServer()
        {
            RemotingConfiguration.RegisterWellKnownServiceType(typeof(Chat),
                            "MULEChatServer",
                            WellKnownObjectMode.Singleton);
        }

       

        static void Main(string[] args)
        {
            Console.WriteLine("\nStarting Server...\n");
            ConsoleServer cServer = new ConsoleServer();
            cServer.StartServer();

            Console.ReadLine();            
        }
    }
}
